﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DONGACS.Common;
using QLPKWeb.BussinessDelegate.CommonDelegate;

using QLPKWeb.BussinessDelegate.HomeDelegate;
using QLPKWeb.BussinessDelegate.LichLamViecDelegate;
//using QLPKWeb.Controllers.Base;
using QLPKWeb.Controllers.Base;

using QLPKWeb.Models.FormBean.HomeMoDel;
using QLPKWeb.Models.LinQ.Home;

namespace QLPKWeb.Controllers
{
    public class HomeController : BaseController
    {
        //
        // GET: /Home/
        HomeDelegate homeDelegate= new HomeDelegate();
     
        CommonDelegate commonDelegate= new CommonDelegate();
        LichLamViecDelegate  LichLamViecDelegate= new LichLamViecDelegate();
      
        //

        public ActionResult Index(int?id)
        {
           
            HomeForm form = new HomeForm();

            //Phần xử lý cho Công việc
         
            //end

            //DateTime Date = form.FromDate != null ? form.FromDate.Value.AddHours(-12) : DateTime.Today.AddHours(-12);
            int day = (int)DateTime.Today.DayOfWeek;
            DateTime FromDate = form.FromDate != null ? commonDelegate.FixDate(form.FromDate.Value, 1) : commonDelegate.FixDate(DateTime.Today.AddDays(-day + 1),1);
            DateTime ToDate = form.FromDate != null ? commonDelegate.FixDate(form.ToDate.Value, 2) : commonDelegate.FixDate(DateTime.Today.AddDays(7 - day), 2);
            CommonDelegate CommonDelegate=new BussinessDelegate.CommonDelegate.CommonDelegate();
            form.ListPhongBan = CommonDelegate.GetAllDepartments().ToList();
            form.ListUser = CommonDelegate.GetAllUsers().ToList();
            form.ListDisplayUser = CommonDelegate.GetUsersByDepartmenId("1").ToList();
            form.ListUserNotInDepartment = CommonDelegate.GetAllUsersNotDepartment().ToList();
            form.ListLichDaDuyet = LichLamViecDelegate.GetAllLichLamViecTheoEventDate(FromDate, ToDate, true);
          
            return View("~/Views/Home/Home.aspx", form);
        }
      
    }
}
